<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ page import="com.gouwudai.gobbs.pojo.TbbsAffiche,com.gouwudai.gobbs.pojo.TbbsClass,com.gouwudai.gobbs.pojo.TbbsTopic,com.gouwudai.gobbs.pojo.TbbsTopicRe,com.gouwudai.gobbs.pojo.TbbsUserInfo" %>
<%@ taglib uri="/tld/extremecomponents" prefix="ec" %>
<%@ include file="../common/common.jsp" %>
<%@ include file="user_pass.jsp" %>
<%
String title = ParamUtils.getStringParameter(request,"title");

int pageIndex = ParamUtils.getIntParameter(request, "pageIndex", 1);
int pageSize = 10;
int classId = ParamUtils.getIntParameter(request, "classId", 0);

int classStyle = 0; //展现样式：BBS还是讨论区风格
if(userLogin.getUserStyle()!=null) //如果用户登陆时设定过样式，则按照用户设置
	classStyle = userLogin.getUserStyle().intValue();
if(request.getParameter("classStyle")!=null)	//如果用户又选择了样式，则按选择的来
{
	classStyle = ParamUtils.getIntParameter(request, "classStyle");
	userLogin.setUserStyle(new Integer(classStyle));
	session.setAttribute("USER_LOGIN",userLogin);	//更新SESSION中的数据
}

String menuStyle = ParamUtils.getStringParameter(request, "menuStyle","CurNew");
String pageUrl = "class.jsp?classId="+classId+"&classStyle="+classStyle+"&menuStyle="+menuStyle+"&";

IClassService classService = (IClassService)BeanManager.getBean("classService");
TbbsClass currentClass = null;
/***************** 权限验证模块 START *********************/
//1.判断当前版面是否存在
try
{
	currentClass = classService.load(new Integer(classId));
}
catch(Exception e)
{
	HtmlConst.errors(out,7,"您浏览的版面不存在或已被删除！");
	return;
}
//判断用户类型
IClassUserService classUserService = (IClassUserService)BeanManager.getBean("classUserService");
int operatorType = 0;//当前用户的类型，0：普通，2：版主
if(classUserService.isClassManager(new Integer(classId),USER_ID))
{
	operatorType = 2;
}

if(operatorType!=2) //非版主用户
{	//判断当前用户是否达到浏览版面所需的等级
	if(userLogin.getGradeId().intValue()<currentClass.getAccessGrade())
	{
		HtmlConst.errors(out,1,"您的级别（"+ Arguments.getUserGradeName(userLogin.getGradeId()) +"）无权查看本页，如果你还没有登陆，请先登陆！");
		return;
	}
	//if(classPro==2)该分类/版面已被锁定，不能浏览
	if(currentClass.getClassPro().intValue()==2)
	{
		HtmlConst.errors(out,9,"该分类/版面已被锁定！");
		return;
	}
	//如果分类/版面需要认证,则需要查询用户是否通过认证
	if(currentClass.getClassPro().intValue()==3)
	{	
		boolean authFlag = classUserService.hasClassAuth(new Integer(classId),userLogin.getUserId());
		if(!authFlag)	
		{
			HtmlConst.errors(out,9,"该分类/版面需要认证！若需要浏览，请联系斑竹");
			return;
		}
	}
	
}
/***************** 权限验证模块 END *********************/

int classType = currentClass.getClassType().intValue();//分类还是版面
int classPro = currentClass.getClassPro().intValue();
String className = currentClass.getClassName();

//目前支持3级栏目
Integer parentId = currentClass.getParentId();//父栏目ID，如果不为空则说明有父栏目
String parentName = "";
TbbsClass parentClass = null;
Integer grandId = null;//二级父栏目ID，如果不为空则说明有父栏目
String grandName = "";
TbbsClass grandIdClass = null;
if(parentId!=null&&parentId.intValue()>0)
{
	parentClass = classService.load(parentId);	
	parentName = parentClass.getClassName();
	grandId = parentClass.getParentId();
}
if(grandId!=null&&grandId.intValue()>0)
{
	grandIdClass = classService.load(grandId);	
	grandName = grandIdClass.getClassName();
}

StringBuilder totalClassName = new StringBuilder(50);//栏目全名，包括父栏目
if(grandId!=null&&grandId.intValue()>0)
{
	totalClassName.append(grandIdClass.getClassName());
	totalClassName.append(" - ");
}
if(parentId!=null&&parentId.intValue()>0)
{
	totalClassName.append(parentClass.getClassName());
	totalClassName.append(" - ");
}
totalClassName.append(currentClass.getClassName());

%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><%=SYSTITLE%> - <%=totalClassName %></title>
<meta name="Keywords" content="<%=SYSMETAKEY%>" />
<meta name="Description" content="<%=SYSMETADESC%>" />
<%@ include file="../common/meta.inc" %>
<link rel="stylesheet" type="text/css" href="css/defaultStyle.css" >
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/extremetable/new/extremecomponents.css"/>
<script language="javascript" type="text/javascript" src="scripts/showMenu.js"></script>
<script language="javascript" type="text/javascript" src="scripts/marquee.js"></script>
</head>
<script language="javascript" type="text/javascript" src="scripts/tree.js"></script>
<body class="<%=menuStyle%>">
<IFRAME id="hiddenframe" style="DISPLAY: none" src="about:blank" width="0"  height="0"></IFRAME>
<%@ include file="../common/waiting.inc" %>
<SCRIPT language="javascript">

setStatus('<%=SYSTITLE%> - <%=totalClassName%>');
</SCRIPT>
<script language="javascript" type="text/javascript" src="template/scripts/topBar.js"></script>
<DIV class="line"></DIV>
<DIV class="list_table_20">
	<span style="float:left">
		<strong>版主:</strong>&nbsp;
		<%
		List managerList = classUserService.listClassManager(classId);
		TbbsUserInfo tbbsUserInfo = null;
		for(int i=0;i<managerList.size();i++)
		{
			tbbsUserInfo = (TbbsUserInfo)managerList.get(i);
			out.print(Arguments.getUserInfoLink(tbbsUserInfo.getLoginId()));
			out.print("&nbsp;&nbsp;");
		}
		%>		
	</span>
	<span style="float:right">
		<a href="/club/pages/class/<%=classId%>.html"><span class="key">静态版</span></a>
		&nbsp;
		<strong><a onmouseover="showmenu(event,'','Menu_Show_style')" href="#" onclick="return false;">显示风格</a></strong>
		<DIV class="showMenu" id="Menu_Show_style" ><UL>
			<li><a href="class.jsp?classId=<%=classId%>&pageIndex=<%=pageIndex%>&classStyle=0&menuStyle=<%=menuStyle%>">BBS风格</a></li>
			<li><a href="class.jsp?classId=<%=classId%>&pageIndex=<%=pageIndex%>&classStyle=1&menuStyle=<%=menuStyle%>">讨区风格</a></li>
		</UL></DIV>
		&nbsp;
		<a href="class.jsp?classId=<%=classId%>&classStyle=<%=classStyle%>&classPro=<%=classPro%>&menuStyle=CurBest" target="_self">精华</a>
		&nbsp;
		<a href="class_manage.jsp?classId=<%=classId%>">管理</a>&nbsp;  
	</span>	
</DIV>
<DIV class="line"></DIV>
<DIV class="list_table_20">	
	<span style="float:left">
		<strong>寄语:</strong>&nbsp;<%=Utility.trimNull(currentClass.getSummary())%>
	</span>
	<span style="float:right">
	<%if(classType==1){%><strong>主题:</strong><%=(currentClass.getTotalTopic().intValue()+currentClass.getTotalReply().intValue())%>&nbsp;<strong>今日主题:</strong><%=(currentClass.getTodayTopic().intValue()+currentClass.getTodayReply().intValue())%>
	<%}%>&nbsp;
	</span>
	
</DIV>
<DIV class="line"></DIV>
<DIV class="list_table_30">	
	<span style="float:right">
	<%
	if(classType==1){%>
		<a href="topic_new.jsp?classId=<%=classId%>"><img src="images/topic.gif" border="0" /></a>
	<%}else{
	List subClassList = classService.listClass(classId,null,new Integer(0));
	TbbsClass subClass = null;
	if(subClassList.size()>0)	{
	%>
	<strong><a onmouseover="showmenu(event,'','Menu_Show_class')" href="#" onclick="return false;">进入小分类发表文章</a></strong>
		<DIV class="showMenu" id="Menu_Show_class" >
		<ul>
		<%
		for(int i=0;i<subClassList.size();i++)
		{	
			subClass = (TbbsClass)subClassList.get(i);
			out.print("<li>");			
			out.print(Arguments.getClassLink(subClass.getClassId(),subClass.getClassName()));
			out.print("</li>");
		}%>	
		</ul>
		</DIV>
	<%}}%>
	</span><DIV class="list_img_left"><strong>公告:</strong>&nbsp;</DIV>
		<div id="marqueeBar" class="marqueeBar" style="float:left">
			<ul>
			<%
				IAfficheService afficheService = (IAfficheService)BeanManager.getBean("afficheService");
				List afficheList = afficheService.listByClassId(classId);
				TbbsAffiche affiche = null;
				for(int i=0;i<afficheList.size();i++) {
					affiche = (TbbsAffiche)afficheList.get(i);
			%>		
				<li><%=Arguments.getAfficheLink(affiche.getAffId(),affiche.getTitle()) %>&nbsp;<span style='color:#990066' ><%=HtmlConst.formatDateHtml(affiche.getCreateDatetime())%></span></li>
			<%}%>
			</ul>
		</div>
	<script type="text/javascript">
	var marqueeBar = new marqueeBarVO("marqueeBar",1);	 //创建对象
	marqueeBar.initMarquee();	
	</script>
</DIV>
<DIV class="line"></DIV>
<DIV class="list_table_0">
	<%=HtmlConst.navMenu(HtmlConst.navClassMenu(new Integer(classId),parentId,grandId,className,parentName,grandName ))%>	
</DIV>
<DIV class="line"></DIV>
<DIV id=Head>
	<DIV id="tabBar">
	<DIV style="float:right">
	  <form name="theform" id="theform" method="get" action="search.jsp" onSubmit="javascript:postMsg();">
	   <input name="title" id="title" type="text" value="<%=title%>" size="12" maxlength="100" />
       <input name="btnQuery" type="button" class="btn" value="检索标题">
	   <input name="classId" type="hidden" value="<%=classId%>" />
      </form>
    </DIV><ul id="tab_bar">
		<li id=menuNew><a href="class.jsp?classId=<%=classId%>&classStyle=<%=classStyle%>&menuStyle=CurNew"><SPAN>最新更新</span></a></li>
		<li id=menuTopic><a href="class.jsp?classId=<%=classId%>&classStyle=<%=classStyle%>&menuStyle=CurTopic"><SPAN>最新发表</span></a></li>
		<li id=menuHot><a href="class.jsp?classId=<%=classId%>&classStyle=<%=classStyle%>&menuStyle=CurHot"><SPAN>热门主题</span></a></li>
		<li id=menuBest><a href="class.jsp?classId=<%=classId%>&classStyle=<%=classStyle%>&menuStyle=CurBest"><SPAN>最新精品</span></a></li>
		<li id=menuAsk><a href="class.jsp?classId=<%=classId%>&classStyle=<%=classStyle%>&menuStyle=CurAsk"><SPAN>最新提问</span></a></li>
		<li id=menuAnswer><a href="class.jsp?classId=<%=classId%>&classStyle=<%=classStyle%>&menuStyle=CurAnswer"><SPAN>最新结贴</span></a></li>
	</ul></DIV>
</DIV>
<%
//--------------头部文件结束-----------------
ITopicService topicService = (ITopicService)BeanManager.getBean("topicService");
ITopicReService topicReService = (ITopicReService)BeanManager.getBean("topicReService");

int totalrows = topicService.listCountByClass(new Integer(classId),menuStyle);  // 总页数

//================BBS风格开始========================
if(classStyle==0){
%>
<DIV class="list_tab_0">
	<DIV class="list_r_0">
		<DIV class="list_0"><span class="text_bold">查阅</span></DIV>
		<DIV class="list_1"><span class="text_bold">回复</span></DIV>
		<DIV class="list_3"><span class="text_bold">作者</span></DIV>
		<DIV class="list_2"><span class="text_bold">最后更新</span></DIV>
		<DIV class="list_none"><span class="text_bold">最后回复</span></DIV>
	</DIV>
	<DIV class="list_center"><span class="text_bold">主题</span></DIV>
</DIV>
<%if(totalrows<=0){%>
	<DIV class="list_tab_1"><center>没有相关文章......</center></DIV>
<%} else{
List topicList = topicService.listByClass(new Integer(classId),menuStyle,pageIndex,pageSize);
TbbsTopic tbbsTopic = null;
for(int i=0;i<topicList.size();i++)
{
	tbbsTopic = (TbbsTopic)topicList.get(i);
%>
<DIV class="list_tab_1">
	<DIV class="list_r_0">
		<DIV class="list_0">
			<span class="smallTxt"><%=tbbsTopic.getTopicViewCount() %></span>
		</DIV>
		<DIV class="list_1">
			<span class="smallTxt"><%=tbbsTopic.getTopicReCount() %></span>
		</DIV>
		<DIV class="list_3">
			<%=Arguments.getUserInfoLink(tbbsTopic.getUserId(),tbbsTopic.getLoginId()) %>
		</DIV>
		<DIV class="list_2">
			<span class="smallTxt"><%=HtmlConst.formatDateHtml(tbbsTopic.getTopicAddTime()) %></span>
		</DIV>
		<DIV class="list_none">
			<%=Arguments.getUserInfoLink(tbbsTopic.getTopicLastReUser()) %>
		</DIV>
	</DIV>
	<DIV class="list_left_2">
		<%=Arguments.getTopicOpenLink(classId,classStyle,tbbsTopic) %>
	</DIV>
	<DIV class="list_left_0">
		<%=Arguments.getTopicMoodDisplay(tbbsTopic.getTopicMood()) %>
	</DIV>
	<DIV class="list_img_left">
		<%=Arguments.getTopicReTree(classId,tbbsTopic.getTopicId()) %>
	</DIV>
	<DIV class="list_img_right">
		<%=Arguments.getTopicHotDisplay(SYSINFO.getIsHottopic().intValue(),SYSINFO.getIsHotre().intValue(),tbbsTopic.getTopicViewCount().intValue(),tbbsTopic.getTopicReCount().intValue()) %>
		<%=Arguments.getTopicTypeDisplay(tbbsTopic.getTopicType(),tbbsTopic.getTopicTypeNum())%>
	</DIV>	
	<DIV class="list_topic">
		<%=Arguments.getTopicLink(tbbsTopic,1) %>
	</DIV>
</DIV>
<DIV  class="list_display_none" style="DISPLAY: none" id="load_<%=tbbsTopic.getTopicId() %>"> 
<DIV style='min-width:600px; margin-left:25px;margin-right:10px;' id='replies_<%=tbbsTopic.getTopicId() %>'> <strong>正在读取此主题相关回复,请稍候......</strong></DIV>
</DIV>
<%}}
//================BBS风格结束========================
}else{
//================讨论区风格开始========================
%><DIV class="list_tab_0">
	<DIV class="list_r_1">
		<DIV class="list_0"><span class="text_bold">查阅</span></DIV>
		<DIV class="list_1"><span class="text_bold">回复</span></DIV>
		<DIV class="list_2"><span class="text_bold">发表时间</span></DIV>
		<DIV class="list_none"><span class="text_bold">型别</span></DIV>
	</DIV>
	<DIV class="list_center"><span class="text_bold">主题</span></DIV>
</DIV>
<%if(totalrows<=0){%>
	<DIV class="list_tab_1"><center>没有相关文章......</center></DIV>
<%}else {
List topicList = topicService.listByClass(new Integer(classId),menuStyle,pageIndex,pageSize);
TbbsTopic tbbsTopic = null;
for(int i=0;i<topicList.size();i++)
{
	tbbsTopic = (TbbsTopic)topicList.get(i);
%>
<DIV class="list_tab_1">
	<DIV class="list_r_1">
		<DIV class="list_0">
			<span class="smallTxt"><%=tbbsTopic.getTopicViewCount() %></span>
		</DIV>
		<DIV class="list_1">
			<span class="smallTxt"><%=tbbsTopic.getTopicReCount() %></span>
		</DIV>
		<DIV class="list_2">
			<span class="smallTxt"><%=HtmlConst.formatDateHtml(tbbsTopic.getTopicAddTime()) %></span>
		</DIV>
		<DIV class="list_3">
			<%=Arguments.getTopicTypeDisplay(tbbsTopic.getTopicType(),tbbsTopic.getTopicTypeNum())%>
		</DIV>
	</DIV>
	<DIV class="list_topic">
		<%=Arguments.getTopicMoodDisplay(tbbsTopic.getTopicMood()) %>
		【<%=Arguments.getUserInfoLink(tbbsTopic.getUserId(),tbbsTopic.getLoginId()) %>】
		<%=Arguments.getTopicLink(tbbsTopic,1) %>
		<%=Arguments.getTopicHotDisplay(SYSINFO.getIsHottopic().intValue(),SYSINFO.getIsHotre().intValue(),tbbsTopic.getTopicViewCount().intValue(),tbbsTopic.getTopicReCount().intValue()) %>
		<%=Arguments.getTopicOpenLink(classId,classStyle,tbbsTopic) %>
		&nbsp;<span class="smallTxt"><i>
		<%=Arguments.getTopicLenDisplay(classId,tbbsTopic.getTopicId().intValue(),tbbsTopic.getTopicReId().intValue(),tbbsTopic.getTopicLen().intValue(),true) %>
		</i></span>
	</DIV>
</DIV>
<!-- 回复内容开始 -->
	<%
	List topicReList = topicReService.listByTopic(tbbsTopic.getTopicId(),1,50);
	TbbsTopicRe tbbsTopicRe = null;
	int reCount = topicReList.size();
	for(int j=0;j<reCount;j++)
	{
		tbbsTopicRe = (TbbsTopicRe)topicReList.get(j);
	%>
	<DIV class=list_tab_2>
	<DIV class="list_r_1">
		<DIV class="list_0">
			<span class="smallTxt">&nbsp;</span>
		</DIV>
		<DIV class="list_1">
			<span class="smallTxt">&nbsp;</span>
		</DIV>
		<DIV class="list_2">
			<span class="smallTxt"><%=HtmlConst.formatDateHtml(tbbsTopicRe.getReAddTime()) %></span>
		</DIV>
		<DIV class="list_3">
			&nbsp;
		</DIV>
	</DIV>
	<DIV class="topic">
			<%=Arguments.getTopicReTreeDisplay(j,reCount) %><%=Arguments.getTopicMoodDisplay(tbbsTopicRe.getReMood()) %>
			〖<%=Arguments.getUserInfoLink(tbbsTopicRe.getUserId(),tbbsTopicRe.getLoginId()) %>〗
			<%=Arguments.getTopicReLink(tbbsTopicRe,1) %>			
			&nbsp;<i class="smallTxt"><%=Arguments.getTopicLenDisplay(classId,tbbsTopicRe.getTopicId().intValue(),tbbsTopicRe.getTopicReId().intValue(),tbbsTopicRe.getReLen().intValue(),true) %></i>
	</DIV>
	</DIV>
	<%} %>
<!-- 回复内容结束 -->
<%}}
}
/* 讨论区风格结束 */
%>
<DIV class="line"></DIV>
<DIV>
	<%=HtmlConst.pageJump(totalrows,pageSize, pageIndex, pageUrl)%>
</DIV>
<DIV class="line"></DIV>
<%@ include file="includes/page_example.inc" %>
<DIV class="line"></DIV>
<%=COPYRIGHTFOOT%>
<%@ include file="../common/foot.inc"%>
</body>
</html>